import { content } from '@/api/software'



export default {
    state: {
        'contactemail': "",
        'online_service': "",
        'opinionmail': "",
        'servicephone': "",
        'sitename': "",
        'software_link': "",
    },
    mutations: {  //mutations是操作state数据的方法的集合，比如对该数据的修改、增加、删除等等
        contactemail(state, data) {
            state.contactemail = data
        },
        onlineservice(state, data) {
            state.online_service = data
        },
        opinionmail(state, data) {
            state.opinionmail = data
        },
        softwarelink(state, data) {
            state.software_link = data
        },
        servicephone(state, data) {
            state.servicephone = data
        },
        sitename(state, data) {
            state.sitename = data
        },
    },
    getters: { //state中的成员加工后传递给外界
        messageUnreadCount: state => state.messageUnreadList.length,
    },
    actions: {//由于直接在mutation方法中进行异步操作，将会引起数据失效。所以提供了Actions来专门进行异步操作，最终提交mutation方法
         // 资产信息
         contentInfo({ state, commit }) {
            return new Promise((resolve, reject) => {
                try {
                    content().then(res => {
                        const data = res.content;
                        commit('contactemail', data.contactemail);
                        commit('onlineservice', data.online_service);
                        commit('opinionmail', data.opinionmail);
                        commit('softwarelink', data.software_link);
                        commit('servicephone', data.servicephone);
                        commit('sitename', data.sitename);
                        resolve(data)
                    }).catch(err => {
                        reject(err)
                    })
                } catch (error) {
                    reject(error)
                }
            })
        },
    }
}
